#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, a[100005], ans, b[100005];
const int p = 998244353;
/*
2 3 4 2 5 0
*/

void dfs(int i, bool flg) {
	if (i == n + 1) {
		if (flg) return;
		int res = 1;
		for (int j = 1; j <= n; ++j) {
			(res *= (a[j] - b[j] + b[(j - 2 + n) % n + 1])) %= p;
		}
		(ans += res) %= p;
		return;
	}
	for (int j = 0; j <= a[i]; ++j) {
		b[i] = j;
		dfs(i + 1, (flg && (j)));
	}
}

signed main() {
	freopen("trade.in", "r", stdin);
	freopen("trade.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	int flg = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		flg &= (a[i] <= 1);
	}
	if (flg) {
		for (int i = 1; i <= n; ++i) {
			if (a[i] != 1) {
				cout << "0\n";
				return 0;
			}
		}
		cout << "1\n";
		return 0;
	} else {
		dfs(1, 1);
		cout << ans << "\n";
	}
	return 0;
}
